package net.midnighttd.game.view;

import net.midnighttd.game.StateChangeListener;
import net.midnighttd.game.GameState;

import javax.swing.*;
import java.awt.*;

/**
 * Author: Adam Scarr
 * Date: 21/04/2009
 * Time: 8:39:07 PM
 */
public class StatBar extends JPanel implements StateChangeListener {
    private MainUI ui;
    private JLabel money = new JLabel();
    private JLabel lives = new JLabel();

    public StatBar(MainUI ui) {
        setLayout(new FlowLayout(FlowLayout.LEFT));
        this.ui = ui;
        setBackground(new Color(73, 86, 63));
        Dimension size = new Dimension(0, 25);
        setMinimumSize(size);
        setPreferredSize(size);
        setMaximumSize(size);

        stateChanged(GameState.MONEY_CHANGED);
        ui.getGame().addStateChangeListener(this);

        JLabel moneyLabel = new JLabel("Money: ");
        Color labelColor = new Color(240, 235,230);
        moneyLabel.setForeground(labelColor);
        add(moneyLabel);
        money.setForeground(labelColor);
        add(money);
        JLabel livesLabel = new JLabel("Lives: ");
        livesLabel.setForeground(labelColor);
        add(livesLabel);
        lives.setForeground(labelColor);
        add(lives);

        
    }

    public void stateChanged(GameState state) {
        if(state == GameState.MONEY_CHANGED || state == GameState.LIVES_CHANGED) {
            money.setText("$" + ui.getGame().getMoney() + ".00");
            lives.setText(Integer.toString(ui.getGame().getLives()));
        }
    }
}
